package com.peas.platform.module.icims.contract.initial.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.peas.platform.framework.mybatisplus.domain.BaseDomain;
import com.peas.platform.framework.mybatisplus.po.BasePo;
import com.peas.platform.framework.mybatisplus.service.BaseServiceImpl;
import com.peas.platform.module.icims.base.approve.dto.ApproveOrderNodeDto;
import com.peas.platform.module.icims.contract.initial.controller.vo.ContractInitialRemindVo;
import com.peas.platform.module.icims.contract.initial.domain.ContractInitialRemindDomain;
import com.peas.platform.module.icims.contract.initial.dto.ContractInitialDto;
import com.peas.platform.module.icims.contract.initial.dto.ContractInitialRemindDto;
import com.peas.platform.module.icims.contract.initial.enums.ContractInitialRemindState;
import com.peas.platform.module.icims.contract.initial.service.ContractInitialRemindService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ContractInitialRemindServiceImpl extends BaseServiceImpl<ContractInitialRemindDto> implements ContractInitialRemindService {

    @Resource
    private ContractInitialRemindDomain contractInitialRemindDomain;

    @Override
    public BaseDomain<ContractInitialRemindDto, ? extends BasePo> getDomain() {
        return contractInitialRemindDomain;
    }

    @Transactional
    @Override
    public void remindContractInitial(ContractInitialDto dto, Long approveId, List<ApproveOrderNodeDto> approveOrderNodes, List<ContractInitialRemindVo> items) {
        items.forEach(v -> {
            ContractInitialRemindDto item = BeanUtil.copyProperties(v, ContractInitialRemindDto.class);
            item.setState(ContractInitialRemindState.save.getKey());
            this.save(item);
        });
    }
}
